package com.wngbms.netty.seatdemo.service;

import com.wngbms.netty.seatdemo.comm.*;
import com.wngbms.netty.seatdemo.message.BaseHeader;
import com.wngbms.netty.seatdemo.message.SeatInMessage;
import com.wngbms.netty.seatdemo.message.SeatOutMessage;
import lombok.extern.slf4j.Slf4j;

import java.io.File;

@Slf4j
public class LargeBinaryStreamUploadTestHandler implements SeatTypeHandler {

    public static final CmdType CMD_TYPE = CmdType.BINARY_TEST_UPLOAD;

    @Override
    public void handleInbound(SeatInMessage seatInMessage) {
        File file = seatInMessage.getFile();
        String absolutePath = file.getAbsolutePath();
        log.info("文件已接收成功 {}", absolutePath);
    }

    @Override
    public void handleOutbound(String userId) {
        String filePath = "J:\\aDrive.exe";
        File file = new File(filePath);
        if (!file.exists()) {
            log.info("{}文件不存在", filePath);
            return;
        }

        int length = (int) file.length();
        BaseHeader baseHeader = BaseHeader.build(MagicVersion.V1, CMD_TYPE, BodyType.BINARY,
                EncryptionType.NON, ReqOrResp.REQ, length);

        SeatOutMessage seatOutMessage = new SeatOutMessage();
        seatOutMessage.setBaseHeader(baseHeader, file);
    }
}
